pp=$(basename $(pwd)); 
id=${pp:11:2}
echo id=$id

if [ $id == 10 -o $id == 20 -o  $id == 30 -o $id == 15 -o $id == 25 ]
    then
    pretag=Renormalized_
fi
pretag=$pretag\cmp

mcid=$( expr $id + 50 )

#rm -f *.eps Frac*.root

pwd > gsi_dir
ls
echo
echo

klogx=0
if [ ${id:0:1} == 1 ]
    then
    klogx=1      
fi

if [ ${id:1:1} == 1 -o ${id:1:1} == 2 ]
then
    klogx=1
fi


for ipar in $(echo 0 2 1 3 )
  do


  kyys=$(echo 0);
  if [ $ipar == 3 ]
      then
      if [ ${id:1:1} == 0 -o ${id:1:1} == 3 ]
      then
          kyys=$(echo 1);
      fi
  fi

  if [ ${id:1:1} == 5 -o ${id:1:1} == 6 ]
  then
      kyys=$(echo 1 0);
  fi

  if [ ${id:1:1} == 0 -o ${id:1:1} == 3 -o ${id:1:1} == 7 ]
  then
      if [ $ipar == 0 -o $ipar == 2 ]
      then
          kyys=$(echo 0 1)
      fi
  fi

  if [ ${id:1:1} == 3 ]
  then
      kyys=0
  fi

  for klogy in $kyys
  do 

#######################################
#IDFF RecMC Jpt
  for mm in $(echo ../TPC* ); do
#  for mm in $(echo ../TPC1TOF4 ); do
      tt=$(basename $mm)
      pp=${tt:0:4}            

      #for jpt in $(echo  5-10 10-15 15-20 20-100  -5-100)
      #for jpt in $(echo  5-10 10-15 15-20  -5-100)
      #for jpt in $(echo 5-6 6-7 7-8 8-9 9-10 10-15 15-20)
      #for jpt in $(echo 5-6 6-7 7-8 8-9 9-10 5-10 10-15 15-20)
      #for jpt in $(echo incl 5-10)
      for jpt in $(echo 5-10 10-15 15-20)
      do

          if [ 1 == 6 -a ${id:0:1} != 0 ]; then
              tag=RecMC$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
#                f3=$(find $pretag*$tt*GrID$mcid*JPT$jpt\_*.root)
              f3=$(find $(echo *$pp\TOF0*JPT$jpt\_directMC_id$mcid.root))
              f2=$(find MC$pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f4=
              f5=
              f6=
              
                    #aliroot -b -l -q 'drawFractionRatio.C("'$tag'",'$ipar', "'$f1'","'$f2'","'$f3'","'$f4'","'$f5'","'$f6'",0,"scaled to ref.",59,'$klogx','$klogy')'
              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy

          fi

          if [ 1 == 1 -a ${id:0:1} != 0 ]; then
              tag=cmpTheo$tt$jpt
              f1=$(find *GrID$id*JPT$jpt*.root)
              f2=$(find outTheory*Perugia0_*JPT$jpt\_*GrID$id*.root)
              f3=$(find outTheory*Perugia2010NoCR_*JPT$jpt\_*GrID$id*.root)
              f4=$(find outTheory*Perugia2011_*JPT$jpt\_*GrID$id*.root)
              f5=
              f6=
              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy
          fi

          if [ 1 == 0 ]; then
              tag=rb1$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f2=$(find rb1$pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy

          fi

          if [ 1 == 2 -a $id == 10 ]; then
              tag=cmpBeta$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f2=$(find Beta*$pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy

          fi

          if [ 1 == 5  ]; then
              tag=cmpGSI$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f2=$(find GSI*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy

          fi

          if [ 1 == 2 -a $id == 10 ]; then
              tag=cmpXmin$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f2=$(find Xmin-9$pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy

          fi

          if [ 1 == 0 -a $id == 10 ]; then
              tag=cmpOLD$tt$jpt
              f1=$(find $pretag*TOF*GrID$id*JPT$jpt\_*.root)
              f2=$(find new$pretag*TOF*GrID$id*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              #./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy
              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          fi

          if [ 1 == 2 -a $id == 10 ]; then
              tag=cmpOLD$tt$jpt
              f1=$(find $pretag*$tt*GrID$id*JPT$jpt\_*.root)
              f2=$(find oldtest$pretag*TOF9*GrID$id*JPT$jpt\_*.root)
              f3=
              f4=
              f5=
              f6=

              #./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 59 $klogx $klogy
              ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          fi
      done


#######################################
      if [ 1 == 0 ]; then
          tag=cmpIncl$tt
          f1=$(find $pretag*$tt*GrID$id*JPT-5-100\_*.root)
          f2=$(find $pretag*$tt*GrID$id*JPT5-10\_*.root)
          f3=$(find $pretag*$tt*GrID$id*JPT20-100\_*.root)
          f4=
          f5=
          f6=
          
            #aliroot -b -l -q 'drawFractionRatio.C("'$tag'",'$ipar', "'$f1'","'$f2'","'$f3'","'$f4'","'$f5'","'$f6'",0,"scaled to ref.",55,'$klogx','$klogy')'
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi
#######################################

      if [ 1 == 1 ]; then
          tag=cmpJpt$tt
          f1=$(find $pretag*$tt*GrID$id*JPT15-20\_*.root)
          f2=$(find $pretag*$tt*GrID$id*JPT10-15\_*.root)
          f3=$(find $pretag*$tt*GrID$id*JPT5-10\_*.root)
          f4=
#$(find $pretag*$tt*GrID$id*JPT20-100\_*.root)
          f5=
          f6=
          
                #aliroot -b -l -q 'drawFractionRatio.C("'$tag'",'$ipar', "'$f1'","'$f2'","'$f3'","'$f4'","'$f5'","'$f6'",0,"scaled to ref.",11,'$klogx','$klogy')'
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi

      if [ 1 == 1 ]; then
          tag=cmpJptRev$tt
          f3=$(find $pretag*$tt*GrID$id*JPT15-20\_*.root)
          f2=$(find $pretag*$tt*GrID$id*JPT10-15\_*.root)
          f1=$(find $pretag*$tt*GrID$id*JPT5-10\_*.root)
          #f1=$(find *GrID$id*JPTincl*.root)
          f4=
          f5=
          f6=          
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi

      if [ 1 == 2 ]; then
          tag=cmpJptTheo2$tt
          f1=$(find outTheory*Perugia2010NoCR_*JPT5-10_*GrID$id*.root)
          f2=$(find outTheory*Perugia2010NoCR_*JPT10-15_*GrID$id*.root)
          f3=$(find outTheory*Perugia2010NoCR_*JPT15-20_*GrID$id*.root)        
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi

      if [ 1 == 0 ]; then
          tag=cmpJptTheo1$tt
          f1=$(find outTheory*Perugia2011_*JPT5-10_*GrID$id*.root)
          f2=$(find outTheory*Perugia2011_*JPT10-15_*GrID$id*.root)
          f3=$(find outTheory*Perugia2011_*JPT15-20_*GrID$id*.root)        
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi

      if [ 1 == 2 ]; then
          tag=cmpJptTheo0$tt
          f1=$(find outTheory*Perugia0_*JPT5-10_*GrID$id*.root)
          f2=$(find outTheory*Perugia0_*JPT10-15_*GrID$id*.root)
          f3=$(find outTheory*Perugia0_*JPT15-20_*GrID$id*.root)        
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi


      if [ 1 == 2 ]; then
          tag=cmpJptB$tt
          f1=$(find $pretag*$tt*GrID$id*JPT10-15\_*.root)
          f2=$(find $pretag*$tt*GrID$id*JPT9-10\_*.root)
          f3=$(find $pretag*$tt*GrID$id*JPT8-9\_*.root)
          f4=$(find $pretag*$tt*GrID$id*JPT7-8\_*.root)
          f5=$(find $pretag*$tt*GrID$id*JPT6-7\_*.root)
          f6=$(find $pretag*$tt*GrID$id*JPT5-6\_*.root)
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi

      if [ 1 == 2 ]; then
          tag=cmpMCJpt$tt
          f1=$(find $(echo *$pp\TOF0*JPT15-20\_directMC_id$mcid.root))
          f2=$(find $(echo *$pp\TOF0*JPT10-15\_directMC_id$mcid.root))
          f3=$(find $(echo *$pp\TOF0*JPT5-10\_directMC_id$mcid.root))
          f4=
          f5=
          f6=

          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 55 $klogx $klogy
      fi
            
  done

#######################################
#
#######################################
        
#  for jpt in $(echo  5-10 10-15 15-20 20-100  -5-100)
  for jpt in $(echo  5-10 10-15 15-20)
  do
      
      if [ 1 == 2 ]; then
#compTPC
          tag=cmpTPC$jpt
          f1=$(find $pretag*TPC1*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC2*GrID$id*JPT$jpt\_*.root)
          f3=
          f4=
          f5=
          f6=
                    #aliroot -b -l -q 'drawFractionRatio.C("'$tag'",'$ipar', "'$f1'","'$f2'","'$f3'","'$f4'","'$f5'","'$f6'",0,"scaled to ref.",7,'$klogx','$klogy')'
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 47 $klogx $klogy
      fi
      
      if [ 1 == 0 ]; then
          
#compTOF
          tag=cmpTOF1$jpt
          f1=$(find $pretag*TPC1TOF9*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC1TOF1*GrID$id*JPT$jpt\_*.root)
          f3=
          f4=
          f5=
          f6=
                    #aliroot -b -l -q 'drawFractionRatio.C("'$tag'",'$ipar', "'$f1'","'$f2'","'$f3'","'$f4'","'$f5'","'$f6'",0,"scaled to ref.",7,'$klogx','$klogy')'
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          tag=cmpTOF2$jpt
          f1=$(find $pretag*TPC1TOF9*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC1TOF2*GrID$id*JPT$jpt\_*.root)
          f3=
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          tag=cmpTOF3$jpt
          f1=$(find $pretag*TPC1TOF9*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC1TOF3*GrID$id*JPT$jpt\_*.root)
          f3=
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          tag=cmpTOF4$jpt
          f1=$(find $pretag*TPC1TOF9*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC1TOF4*GrID$id*JPT$jpt\_*.root)
          f3=
          f4=
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy

          tag=cmpTOFall$jpt
          f1=$(find $pretag*TPC1TOF9*GrID$id*JPT$jpt\_*.root)
          f2=$(find $pretag*TPC1TOF2*GrID$id*JPT$jpt\_*.root)
          f3=$(find $pretag*TPC1TOF3*GrID$id*JPT$jpt\_*.root)
          f4=$(find $pretag*TPC1TOF4*GrID$id*JPT$jpt\_*.root)
          f5=
          f6=
          ./drawFractionRatio "$tag" $ipar  "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" 0 "scaled to ref." 27 $klogx $klogy
      fi                    
  done
  
done

done


